package vrp;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;


import vrp.PMF;
import vrp.Carrier;

public class CarrierDeleteServlet extends HttpServlet {

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
    	
    	PersistenceManager pm = PMF.get().getPersistenceManager();
    	
        long keyid = Integer.parseInt(req.getParameter("key"));
        
        Key key = KeyFactory.createKey(Carrier.class.getSimpleName(), keyid);
        Carrier carrier = pm.getObjectById(Carrier.class, key);

        //check certain cases when cannot delete the carrier
        
        
        try {
            pm.deletePersistent(carrier);
        } finally {
            pm.close();
        }
        resp.sendRedirect("/carriers.jsp");
    }
}
